package com.we823.project.repository.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.we823.project.model.UserStationModel;
import com.we823.project.repository.dao.UserStationRepository;

@Service("userStationService")
public class UserStationService extends AbstractBaseService<UserStationModel> {

	private UserStationRepository userStationRepository;
	
	@Autowired
	public UserStationService(UserStationRepository userStationRepository) {
		super(userStationRepository);
		this.userStationRepository = userStationRepository;
	}

	public List<UserStationModel> findByUserId(int userId) {
		return userStationRepository.findByUserId(userId);
	}

	public List<UserStationModel> findByStationId(int stationId) {
		return userStationRepository.findByStationId(stationId);
	}

	public Map<Integer, UserStationModel> map() {
		List<UserStationModel> userStationModels = findAll();
		Map<Integer,UserStationModel> map = new HashMap<Integer, UserStationModel>();
		if(userStationModels!=null) {
			for (UserStationModel userStationModel : userStationModels) {
				map.put(userStationModel.getUserId(), userStationModel);
			}
		}
		return map;
	}

	public UserStationModel findByUserIdAndStationId(Integer userId,
			Integer stationId) {
		return userStationRepository.findByUserIdAndStationId(userId,stationId);
	}

}
